/**  
 * @Title: DataUtil.java
 * @Package org.csun.nc.utils
 * @Description: TODO
 * @author chisj chisj@foxmail.com
 * @date 2017年9月18日
 */
package com.csun.cmny.provider.utils;

import com.csun.cmny.provider.model.entity.TimeRange;
import org.junit.Test;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * ClassName: DataUtil 
 * @Description: TODO
 * @author chisj chisj@foxmail.com
 * @date 2017年9月18日
 */
public class DateUtil {
	
	public final static DateFormat YYYY_MM_DD_MM_HH_SS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public final static DateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
	
	public final static DateFormat YYYYMMDDMMHHSSSSS = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	
	public final static DateFormat YYYYMMDDHHMMSS = new SimpleDateFormat("yyyyMMddHHmmss");

	public static final DateFormat YYYYMMDD = new SimpleDateFormat("yyyyMMdd");
	
	public static final DateFormat MMDDHHMMSS =  new SimpleDateFormat("MMddHHmmss");
	
	public static final DateFormat HHMMSS = new SimpleDateFormat("HHmmss");

	public final static DateFormat H002_YYYYMMDDHHMMSS = new SimpleDateFormat("yyyyMMddHHmmss");

	public final static DateFormat H002_YYYYMMDDHHMM = new SimpleDateFormat("yyyyMMddHHmm");

	public final static DateFormat HH_HH_SS = new SimpleDateFormat("HH:mm:ss");

	public static String getCurrentDate() {

		return YYYY_MM_DD_MM_HH_SS.format(new Date());
	}

	public static String getCurrentTime() {

		return HH_HH_SS.format(new Date());
	}

	public static byte[] getDate() {

		Calendar calendar = Calendar.getInstance();
		byte year_end = (byte)(calendar.get(Calendar.YEAR) % 100);
		byte year_start = (byte)(calendar.get(Calendar.YEAR) / 100);
		byte month = (byte)(calendar.get(Calendar.MONTH) + 1);
		byte day = (byte)(calendar.get(Calendar.DAY_OF_MONTH));
		byte hour = (byte)(calendar.get(Calendar.HOUR_OF_DAY));
		byte minute = (byte)(calendar.get(Calendar.MINUTE));
		byte second = (byte)(calendar.get(Calendar.SECOND));

		byte[] date = new byte[]{second, minute, hour, day, month, year_end, year_start};

		return date;
	}

	public static Date getDate(byte[] date) {

		Calendar calendar = Calendar.getInstance();

		int year_start = (int)date[6];
        int year_end = (int)date[5];
		int year = Integer.parseInt(year_start + "" + year_end);
		int month = (int)date[4];
		int day = (int)date[3];
		int hour = (int)date[2];
		int minute = (int)date[1];
		int second = (int)date[0];

		calendar.set(year, month - 1, day, hour, minute, second);

		return calendar.getTime();
	}

	public static String dateToStrs(Date date) {
		return HHMMSS.format(date);
	}

	/**
	 * 获取yyyyMMddHHmmss的时间
	 */
	public static String nowDateStr() {

		H002_YYYYMMDDHHMMSS.setTimeZone(TimeZone.getTimeZone("Etc/GMT"));

		return H002_YYYYMMDDHHMMSS.format(new Date());
	}

	public static String getDateStr(Date date) {

		return YYYYMMDDHHMMSS.format(date);
	}

	/**
	 * 时间转换为yyyyMMddHHmmss格式
	 */
	public static String dateToStringss(Date date) {
		return MMDDHHMMSS.format(date);
	}
	
	/**
	 * 时间转换为yyyyMMddHHmmss格式
	 */
	public static String dateToStrings(Date date) {
		return YYYYMMDDMMHHSSSSS.format(date);
	}
	
	/**
	 * 时间转换为yyyy-MM-dd HH:mm:ss格式的字符串
	 * @param date
	 * @return
	 */
	public static String dateToString(Date date){
		return YYYY_MM_DD_MM_HH_SS.format(date);
	}
	
	public static String dateToStr(Date date){
		return YYYY_MM_DD.format(date);
	}
	
	
	public static Date stringToDate(String dateString){
		Date date = null;
		try {
			date = YYYY_MM_DD.parse(dateString);
		} catch (ParseException e) {
			//System.out.println("dateString = " + dateString);
			e.printStackTrace();
		}
		return date;
	}
	
	
	public static Date strToDate(String dateString){
		Date date = null;
		try {
			date = YYYY_MM_DD_MM_HH_SS.parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	public static Date strToYYMMDDDate(String dateString){
		Date date = null;
		try {
			date = YYYY_MM_DD.parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	/**
	 * 计算两个时间之间相差的天数
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static long diffDays(Date startDate,Date endDate){
		long days = 0;
		long start = startDate.getTime();
		long end = endDate.getTime();
		//一天的毫秒数1000 * 60 * 60 * 24=86400000
		days = (end - start) / 86400000;
		return days;
	}
	
	/**
	 * 日期加上月数的时间
	 * @param date
	 * @param month
	 * @return
	 */
	public static Date dateAddMonth(Date date,int month){
		return add(date,Calendar.MONTH,month);
	}
	
	/**
	 * 日期加上天数的时间
	 * @param date
	 * @param day
	 * @return
	 */
	public static Date dateAddDay(Date date,int day){
		return add(date,Calendar.DAY_OF_YEAR,day);
	}

	public static Date dateAdd(Date date,int day){
		Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
		ca.setTime(date); //设置时间为当前时间
		ca.add(Calendar.DATE, day); //
		return ca.getTime();
	}
	
	/**
	 * 日期加上年数的时间
	 * @param date
	 * @param year
	 * @return
	 */
	public static Date dateAddYear(Date date,int year){
		return add(date,Calendar.YEAR,year);
	}
	
	 /** 
     * 计算剩余时间 (多少天多少时多少分)
     * @param startDate
     * @param endDate
     * @return 
     */  
    public static String remainDateToString(Date startDate, Date endDate){  
    	StringBuilder result = new StringBuilder();
    	if(endDate == null ){
    		return "过期";
    	}
    	long times = endDate.getTime() - startDate.getTime();
    	if(times < -1){
    		result.append("过期");
    	}else{
    		long temp = 1000 * 60 * 60 *24;
    		//天数
    		long d = times / temp;

    		//小时数
    		times %= temp;
    		temp  /= 24;
    		long m = times /temp;
    		//分钟数
    		times %= temp;
    		temp  /= 60;
    		long s = times /temp;
    		
    		result.append(d);
    		result.append("天");
    		result.append(m);
    		result.append("小时");
    		result.append(s);
    		result.append("分");
    	}
    	return result.toString();
    }  
    
    
    /** 
     * 计算剩余时间 (多少天多少时多少分)
     * @param startDate
     * @param endDate
     * @return 
     */  
    public static String remainDateToString2(Date startDate, Date endDate){  
    	StringBuilder result = new StringBuilder();
    	if(endDate == null ){
    		return "竞拍结束";
    	}
    	long times = endDate.getTime() - startDate.getTime();
    	if(times < -1){
    		result.append("竞拍结束");
    	}else{
    		long temp = 1000 * 60 * 60 *24;
    		//天数
    		long d = times / temp;

    		//小时数
    		times %= temp;
    		temp  /= 24;
    		long m = times /temp;
    		//分钟数
    		times %= temp;
    		temp  /= 60;
    		long s = times /temp;
    		
    		result.append(d);
    		result.append("天");
    		result.append(m);
    		result.append("小时");
    		result.append(s);
    		result.append("分");
    	}
    	return result.toString();
    }  
    
    
	private static Date add(Date date,int type,int value){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(type, value);
		calendar.add(1,1);
		return calendar.getTime();
	}

	public static String getDay() {

    	StringBuilder sb = new StringBuilder();

		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());

		int day = calendar.get(Calendar.DAY_OF_MONTH);
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		int minute = calendar.get(Calendar.MINUTE);

		sb.append(day);
		sb.append("日");
		sb.append(hour);
		sb.append("时");
		sb.append(minute);
		sb.append("分");

		return sb.toString();
	}

	@Test
	public void main() {

		System.out.println(getDay());
	}
	
	/**   
	 * @MethodName: getLinkUrl  
	 * @Param: DateUtil  
	 * flag ： true 转换  false 不转换
	 * @Author: gang.lv
	 * @Date: 2013-5-8 下午02:52:44
	 * @Return:    
	 * @Descb: 
	 * @Throws:
	*/
	public static String getLinkUrl(boolean flag,String content,String id){
		if(flag){
			content = "<a href='finance.do?id="+id+"'>"+content+"</a>";
		}
		return content;
	}
	
	/**
	 * 时间转换为时间戳
	 * @param format
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public static long getTimeCur(String format,String date) throws ParseException{
		SimpleDateFormat sf = new SimpleDateFormat(format);
		return  sf.parse(sf.format(date)).getTime();
	}
	/**
	 * 时间转换为时间戳
	 * @param format
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public static long getTimeCur(String format,Date date) throws ParseException{
		SimpleDateFormat sf = new SimpleDateFormat(format);
		return  sf.parse(sf.format(date)).getTime();
	}
	
	/**
	 * 将时间戳转为字符串 
	 * @param cc_time
	 * @return
	 */
	public static String getStrTime(String cc_time) { 
	 String re_StrTime = null; 
	 SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); 
	 long lcc_time = Long.valueOf(cc_time); 
	 re_StrTime = sdf.format(new Date(lcc_time * 1000L)); 
	 return re_StrTime; 
	 } 
	
	public static Timestamp strToTime(String date) {
		Calendar calendar = Calendar.getInstance();
		String dateStr = String.valueOf(calendar.get(Calendar.YEAR));
		dateStr = dateStr + date.substring(date.lastIndexOf("-")) + "-10";
		//System.out.println(dateStr);//得到年
		String curr_time_d = YYYY_MM_DD_MM_HH_SS.format(stringToDate(dateStr));
		Timestamp timestamp = Timestamp.valueOf(curr_time_d);
		return timestamp;
	}
	
	public static String getAge(String birthDay) throws Exception {
		
		SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
		  Date date=new Date();
		  Date mydate= myFormatter.parse("2010-6-15");
		  long day=(date.getTime()-mydate.getTime())/(24*60*60*1000) + 1;
		  return new java.text.DecimalFormat("#").format(day/365);
		
	}
	
	// 获取当前周的周一
	public static String getCurrMon() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式
		Calendar cld = Calendar.getInstance(Locale.CHINA); // 获取日历
		cld.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 设置日历当前时间为一周内周一的日期
		return sdf.format(cld.getTime()); // 获取日历时间
	}
	
	// 获取指定日期的周一
	public static String getMonByDate(String date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cld = Calendar.getInstance(Locale.CHINA);
		String imptimeBegin = "";
		try {
			cld.setTime(sdf.parse(date));
			int dayWeek = cld.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			if (1 == dayWeek) {
				cld.add(Calendar.DAY_OF_MONTH, -1);
			}
			// System.out.println("要计算日期为:"+sdf.format(cld.getTime()));
			// //输出要计算日期
			cld.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
			int day = cld.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			cld.add(Calendar.DATE, cld.getFirstDayOfWeek() - day);// 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
			imptimeBegin = sdf.format(cld.getTime());
			// System.out.println("所在周星期一的日期："+imptimeBegin);
			cld.add(Calendar.DATE, 6);
			String imptimeEnd = sdf.format(cld.getTime());
			// System.out.println("所在周星期日的日期："+imptimeEnd);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return imptimeBegin;
	}
	/** 计算年龄 */ 
	public static  String getAge(Date birthDay) throws Exception {
		Calendar cal = Calendar.getInstance();
		
		if (cal.before(birthDay)) {
			throw new IllegalArgumentException(
				"The birthDay is before Now.It's unbelievable!");
	        } 

	        int yearNow = cal.get(Calendar.YEAR); 
	        int monthNow = cal.get(Calendar.MONTH)+1; 
	        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH); 
	        
	        cal.setTime(birthDay); 
	        int yearBirth = cal.get(Calendar.YEAR); 
	        int monthBirth = cal.get(Calendar.MONTH); 
	        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH); 
            
	        int age = yearNow - yearBirth; 

	        if (monthNow <= monthBirth) { 
	            if (monthNow == monthBirth) { 
	                //monthNow==monthBirth 
	                if (dayOfMonthNow < dayOfMonthBirth) {
	                    age--; 
	                } 
	            } else { 
	                //monthNow>monthBirth 
	                age--; 
	            } 
	        } 

	        return age +""; 
	    }
	
	/** 计算年龄 */ 
	public static  String getMonth(Date birthDay) throws Exception {
		Calendar cal = Calendar.getInstance();
		
		if (cal.before(birthDay)) {
			throw new IllegalArgumentException(
				"The birthDay is before Now.It's unbelievable!"); 
	        } 

	        int yearNow = cal.get(Calendar.YEAR); 
	        int monthNow = cal.get(Calendar.MONTH)+1;
	        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH); 
	        
	        cal.setTime(birthDay); 
	        int yearBirth = cal.get(Calendar.YEAR); 
	        int monthBirth = cal.get(Calendar.MONTH)+1;
	        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH); 

	        int age = yearNow - yearBirth;
	        int month=monthNow-monthBirth;

	        if (monthNow <= monthBirth) {
	            if (monthNow == monthBirth) {
	                //monthNow==monthBirth 
	                if (dayOfMonthNow < dayOfMonthBirth) {
	                    age--; 
	                    month=11;
	                } else {
	                	
	                    month=0;
	                }
	            } else{ 
	                //monthNow>monthBirth 
	                age--; 
	                if (dayOfMonthNow >= dayOfMonthBirth){
	                	month=12-(monthBirth-monthNow);
	            } else{
	            	//System.out.println("44");
	            	month=12-(monthBirth-monthNow)-1;
	            }
	        }
	        }else{
	        	if (dayOfMonthNow >= dayOfMonthBirth){
                	month=monthNow-monthBirth;
                	}else{
                		month=monthNow-monthBirth-1;
                	}
	        }
	        //System.out.println("age = " + age);
	        if(age==0){
	        	if(monthNow < monthBirth){
	        	if(dayOfMonthNow >= dayOfMonthBirth){
	        		month=12-(monthBirth-monthNow);
	        	}else{
	        		month=11-(monthBirth-monthNow);
	        	}
	        	}else{
	        		//if(monthNow == monthBirth){
	        		//	month=11;
	        		//}
	        		
	        	}
	        }
	        String age_1="0";
	
	        	age_1=age + "岁"+month + "个月";
	        

	        return age_1;
	    }

	    /*
	    * 将日期字符串处理，返回date类型的前一天12:00到今日12:00的数据
	    * */
	    public static TimeRange getYesterDayAndTodayDate(String date){

	    	date = date.concat(" 12:00:00");
	    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①

			try {

				TimeRange timeRange = new TimeRange();
				Date endDate = sdf.parse(date);
				timeRange.setEndTime(endDate);

				Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
				ca.setTime(endDate); //设置时间为当前时间
				ca.add(Calendar.DATE, -1); //日期减一，前几天就减几
				Date startDate = ca.getTime();

				timeRange.setStartTime(startDate);
				return timeRange;
			}catch(ParseException e) {
				e.printStackTrace();
			}
			return null;
		}

		//获取时间对象前推一定秒数后的时间
		public static Date dateSubstractSeconds(Date time,int second){
	    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①

			try {
				Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
				ca.setTime(time); //设置时间为当前时间
				ca.add(Calendar.SECOND, 0-second); //日期减一，前几天就减几
				return ca.getTime();
			}catch(Exception e) {
				e.printStackTrace();
			}
			return null;
		}

	//获取时间对象前推一定秒数后的时间
	public static Date dateAddSeconds(Date time,int second){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①
		try {
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
			ca.setTime(time); //设置时间为当前时间
			ca.add(Calendar.SECOND, second); //日期减一，前几天就减几
			return ca.getTime();
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	//获取时间对象前推一定天数后的时间
	public static Date dateSubstractDays(Date time,int days){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//①

		try {
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
			ca.setTime(time); //设置时间为当前时间
			ca.add(Calendar.DATE, 0-days); //日期减一，前几天就减几
			return ca.getTime();
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static Date dateAddMinute(Date time,int minute){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①

		try {
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
			ca.setTime(time); //设置时间为当前时间
			ca.add(Calendar.MINUTE, minute);
			return ca.getTime();
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

		//将日期字符串转化为前一天特定时间的Date对象
		public static Date transformDateStringToYesterDayDate(String date,String time){

			date = date.concat(" "+time);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①

			try {

				Date newDate = sdf.parse(date);
				Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
				ca.setTime(newDate); //设置时间为当前时间
				ca.add(Calendar.DATE, -1); //日期减一，前几天就减几
				return ca.getTime();
			}catch(ParseException e) {
				e.printStackTrace();
			}
			return null;
		}

	//将日期字符串转化为当天特定时间的Date对象
	public static Date transformDateStringToDate(String date,String time){

		date = date.concat(" "+time);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①
		try {
			return sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	/*
	 * 返回今日和七日前的Date类型
	 * */
	public static TimeRange getTodayDateAndBeforeSevenDaysDate(String date){

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//①

		try {

			TimeRange timeRange = new TimeRange();
			Date realDate = sdf.parse(date);

			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
			ca.setTime(realDate); //设置时间为当前时间
			ca.add(Calendar.DATE, -1); //日期减一，前几天就减几

			timeRange.setEndTime(ca.getTime());

			ca.add(Calendar.DATE, -6); //日期减一，前几天就减几
			timeRange.setStartTime(ca.getTime());

			return timeRange;
		}catch(ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	//计算两个时间的差值
	public static Double calculateSubtract(String startTime ,String endTime){

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//①
		try {

			Date startDate = sdf.parse(startTime);
			Date endDate = sdf.parse(endTime);

			double result = ((double) (endDate.getTime() - startDate.getTime()))/(1000*60);
			return result;
		}catch(ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String getYearAndMonth() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); // 设置时间格式
		return sdf.format(date); // 获取日历时间
	}

	/**
	 * 判断是否在非睡眠时间 0时区
	 *
	 * @param sleepTime
	 * @return
	 */
	public static boolean isNotSleepTime(String sleepTime) {
		// TODO Auto-generated method stub

		String sleep = sleepTime.substring(8, 12);

		if (sleep.compareTo("0400") >= 0 && sleep.compareTo("1200") <= 0) {
			return true;
		} else {
			return false;
		}

	}

	public static String getSleepDate(String sleepEnd) {

		// TODO Auto-generated method stub
		Date sleepNow = null;
		String sleepEndTime = sleepEnd.substring(8, 12);
		try {
			Date end = H002_YYYYMMDDHHMM.parse(sleepEnd);

			Calendar cld = Calendar.getInstance();
			cld.setTime(end);

			if (sleepEndTime.compareTo("0000") >= 0 && sleepEndTime.compareTo("0400") <= 0) {
				cld.add(Calendar.DATE, -1);
				sleepNow = cld.getTime();
			} else {
				sleepNow = end;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}


		return YYYY_MM_DD.format(sleepNow);
	}

	public static String getSleepTimeZone(String sleepDate, String timeZone) {

		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");  //
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmm");

		Date sleep = null;
		try {
			sleep = sdf2.parse(sleepDate);
		} catch (Exception e) {
			e.printStackTrace();
		}

		boolean flag = true;

		switch (timeZone) {
			case "0" :
				break;
			case "+1" :
				flag = false;
				sleep = new Date(sleep.getTime() + (1 * 3600) * 1000);
				break;
			case "+2" :
				flag = false;
				sleep = new Date(sleep.getTime() + (2 * 3600) * 1000);
				break;
			case "+3" :
				flag = false;
				sleep = new Date(sleep.getTime() + (3 * 3600) * 1000);
				break;
			case "+3.5" :
				flag = false;
				sleep = new Date(sleep.getTime() + (3 * 3600 + 30 * 60) * 1000);
				break;
			case "+4" :
				flag = false;
				sleep = new Date(sleep.getTime() + (4 * 3600) * 1000);
				break;
			case "+4.5" :
				flag = false;
				sleep = new Date(sleep.getTime() + (4 * 3600 + 30 * 60) * 1000);
				break;
			case "+5" :
				flag = false;
				sleep = new Date(sleep.getTime() + (5 * 3600) * 1000);
				break;
			case "+5.5" :
				flag = false;
				sleep = new Date(sleep.getTime() + (5 * 3600 + 30 * 60) * 1000);
				break;
			case "+5.75" :
				flag = false;
				sleep = new Date(sleep.getTime() + (5 * 3600 + 45 * 60) * 1000);
				break;
			case "+6" :
				flag = false;
				sleep = new Date(sleep.getTime() + (6 * 3600) * 1000);
				break;
			case "+6.5" :
				flag = false;
				sleep = new Date(sleep.getTime() + (6 * 3600 + 30 * 60) * 1000);
				break;
			case "+7" :
				flag = false;
				sleep = new Date(sleep.getTime() + (7 * 3600) * 1000);
				break;
			case "+8" :
				flag = false;
				sleep = new Date(sleep.getTime() + (8 * 3600) * 1000);
				break;
			case "+9" :
				flag = false;
				sleep = new Date(sleep.getTime() + (9 * 3600) * 1000);
				break;
			case "+10" :
				flag = false;
				sleep = new Date(sleep.getTime() + (10 * 3600) * 1000);
				break;
			case "+11" :
				flag = false;
				sleep = new Date(sleep.getTime() + (11 * 3600) * 1000);
				break;
			case "+12" :
				flag = false;
				sleep = new Date(sleep.getTime() + (12 * 3600) * 1000);
				break;
			case "-1" :
				flag = false;
				sleep = new Date(sleep.getTime() - (1 * 3600) * 1000);
				break;
			case "-2" :
				flag = false;
				sleep = new Date(sleep.getTime() - (2 * 3600) * 1000);
				break;
			case "-3" :
				flag = false;
				sleep = new Date(sleep.getTime() - (3 * 3600) * 1000);
				break;
			case "-3.5" :
				flag = false;
				sleep = new Date(sleep.getTime() - (3 * 3600 + 30 * 60) * 1000);
				break;
			case "-4" :
				flag = false;
				sleep = new Date(sleep.getTime() - (4 * 3600) * 1000);
				break;
			case "-4.5" :
				flag = false;
				sleep = new Date(sleep.getTime() - (4 * 3600 + 30 * 60) * 1000);
				break;
			case "-5" :
				flag = false;
				sleep = new Date(sleep.getTime() - (5 * 3600) * 1000);
				break;
			case "-5.5" :
				flag = false;
				sleep = new Date(sleep.getTime() - (5 * 3600 + 30 * 60) * 1000);
				break;
			case "-5.75" :
				flag = false;
				sleep = new Date(sleep.getTime() - (5 * 3600 + 45 * 60) * 1000);
				break;
			case "-6" :
				flag = false;
				sleep = new Date(sleep.getTime() - (6 * 3600) * 1000);
				break;
			case "-6.5" :
				flag = false;
				sleep = new Date(sleep.getTime() - (6 * 3600 + 30 * 60) * 1000);
				break;
			case "-7" :
				flag = false;
				sleep = new Date(sleep.getTime() - (7 * 3600) * 1000);
				break;
			case "-8" :
				flag = false;
				sleep = new Date(sleep.getTime() + (8 * 3600) * 1000);
				break;
			case "-9" :
				flag = false;
				sleep = new Date(sleep.getTime() - (9 * 3600) * 1000);
				break;
			case "-10" :
				flag = false;
				sleep = new Date(sleep.getTime() - (10 * 3600) * 1000);
				break;
			case "-11" :
				flag = false;
				sleep = new Date(sleep.getTime() - (11 * 3600) * 1000);
				break;
			case "-12" :
				flag = false;
				sleep = new Date(sleep.getTime() - (12 * 3600) * 1000);
				break;
		}

		// 时区转换有问题
//		if (flag) {
//			TimeZone tz = TimeZone.getTimeZone("Etc/GMT" + timeZone);
//			sdf1.setTimeZone(tz);
//		}

		return sdf1.format(sleep);
	}

	public static String sleepAdd(String sleep_1, String sleep_2) {
		// TODO Auto-generated method stub

		String str = "";
		Formatter fm = new Formatter();

		int a = sleep_1.equals("0000")
				? 0
				: Integer.parseInt(sleep_1.substring(0, 2)) * 3600  +
				Integer.parseInt(sleep_1.substring(2, 4))  * 60;

		int b = sleep_2.equals("0000")
				? 0
				: Integer.parseInt(sleep_2.substring(0, 2)) * 3600  +
				Integer.parseInt(sleep_2.substring(2, 4))  * 60;

		int total = a + b;

		int hours = total / 3600;
		int minutes = (total / 60) % 60;

		if (hours > 0) {
			str = fm.format("%02d%02d", hours, minutes).toString();
		} else {
			str = fm.format("00%02d", minutes).toString();
		}

		fm.close();

		return str;
	}
}
